package org.flyframework.command
{
	import flash.events.Event;
	
	
	public dynamic class DynamicCommand extends CommandBase
	{
		
		public var executeHandler:Function = null;
		public var undoHandler:Function = null;
		public var redoHandler:Function = null;
		
		
		//--------------------------------------------------------------------------
		// Init
		//--------------------------------------------------------------------------
		
		public function DynamicCommand( name:String=null, execHandler:Function=null, undoHandler:Function=null, canRedo:Boolean=true )
		{
			super( name );
			
			this.executeHandler = execHandler;
			this.undoHandler = undoHandler;
			
			if( canRedo == true )
			{
				this.redoHandler = execHandler;
			}
		}
		
		
		//--------------------------------------------------------------------------
		// ICommand
		//--------------------------------------------------------------------------
		
		override public function execute( event:Event=null ):void
		{
			if( this.executeHandler != null )
			{
				this.executeHandler( event );
			}
		}
		
		override public function undo( event:Event=null ):void
		{
			if( this.undoHandler != null )
			{
				this.undoHandler( event );
			}
		}
		
		override public function canUndo():Boolean
		{
			return( this.undoHandler != null );
		}
		
		override public function redo( event:Event=null ):void
		{
			if( this.redoHandler != null )
			{
				this.redoHandler( event );
			}
		}
		
		override public function canRedo():Boolean
		{
			return( this.redoHandler != null );
		}
		
	}
}